<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">反馈内容重复录入检测</h4>
</div>
<div class="modal-body">
    <div class="row">
        <div class="form-group" style="padding-bottom: 30px;">
            <div class="col-sm-10">
                <textarea name="check_content" rows="8" cols="75" placeholder="反馈内容原文"></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-10">
                <p>检测结果：<span id="check-result"></span><span id="link-to-add" style="display: none">，<a target="_blank" href="/xqc/quality/complaint/create">去添加</a></span></p>
                <button type="submit" style="margin-left: 50%;" class="btn btn-twitter" id="check-submit"><span id="loading">检测</span></button>
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $("#check-result").text('待检测');
        $('textarea[name="check_content"]').on("input propertychange", function() {
            $("#check-result").text('待检测').css('color','#444');
            $("#link-to-add").css('display','none');
        });
        $('#check-submit').on('click', function(e) {
            e.preventDefault();
            var content = $('textarea[name="check_content"]').val().trim();
            if(content == ''){
                $("#check-result").text('反馈内容不能为空').css('color','red');
                return false;
            }
            $.ajax({
                method: 'post',
                url: '/xqc/quality/complaint-ajax',
                data: {
                    _token:"{{ csrf_token() }}",
                    action:'doCheckContent',
                    param:content
                },
                beforeSend: function(){
                    $('#loading').text('检测中。。。');
                    $('#check-submit').attr('disabled',true);
                },
                success: function (data) {
                    $('#loading').text('检测');
                    $('#check-submit').removeAttr('disabled');
                    if (typeof data === 'object') {
                        if (data.status) {
                            $("#check-result").text(data.message).css('color','blue');
                        } else {
                            $("#check-result").text(data.message).css('color','red');
                            $("#link-to-add").css('display','inline');
                        }
                    }
                }
            });
        });
    });
</script>
